package vn.conghuy.talkwithme.data.android;

import java.util.ArrayList;

public class ContactModel {
	/**
	 * @uml.property  name="name"
	 */
	String name;
	/**
	 * @uml.property  name="address"
	 */
	String address;
	/**
	 * @uml.property  name="id"
	 */
	int id;
	
	public ContactModel(int id, String name, String address) {
		super();
		this.id = id;
		this.name = name;
		this.address = address;
	}
	
	/**
	 * @return
	 * @uml.property  name="name"
	 */
	public String getName() {
		return name;
	}
	/**
	 * @param name
	 * @uml.property  name="name"
	 */
	public void setName(String name) {
		this.name = name;
	}
	/**
	 * @return
	 * @uml.property  name="address"
	 */
	public String getAddress() {
		return address;
	}
	/**
	 * @param address
	 * @uml.property  name="address"
	 */
	public void setAddress(String address) {
		this.address = address;
	}

	/**
	 * @return
	 * @uml.property  name="id"
	 */
	public int getId() {
		return id;
	}

	/**
	 * @param id
	 * @uml.property  name="id"
	 */
	public void setId(int id) {
		this.id = id;
	}
	
	public static String[] arrayListContactModelToStringArray(ArrayList<ContactModel> lContact){
		String[] aContact = new String[lContact.size()];
		int i = 0;
		for(ContactModel contact: lContact){
			aContact[i] = contact.getName();
			i++;
		}
		return aContact;
	}
	
	public static ContactModel isStringBeSubStringOfNameOfAnElementInArray(String strName, ArrayList<ContactModel> lContacts){
		for(ContactModel contact : lContacts){
			if(contact.getName().toLowerCase().contains(strName.toLowerCase()))
				return contact;
		}
		
		return null;
	}
	
	public static ContactModel isExistElemInArrayHasNameBeSubStringOfStr(ArrayList<ContactModel> lContacts, String strName){
		for(ContactModel contact : lContacts){
			if(strName.toLowerCase().contains(contact.getName().toLowerCase()))
				return contact;
		}
		return null;
	}
	
	public static ArrayList<ContactModel> isExistWordInContactEqualWordInString(ArrayList<ContactModel> lContacts, String strName){
		ArrayList<ContactModel> lResult = new ArrayList<ContactModel>();
		String[] nameWords = strName.toLowerCase().split(" ");
		for(ContactModel contact : lContacts){
			String[] contactNames = contact.getName().toLowerCase().split(" ");
			for(String name: nameWords){
				for(String contactName: contactNames){
					if(name.equals(contactName))
						lResult.add(contact);
				}
			}
		}
		return lResult;
	}
}
